﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KandaAlpha.Application.Interfaces;
using KandaAlpha.Domain.Model.Entities;

namespace KandaAlpha.UI.Mvc.Controllers
{

    /// <summary>
    /// Base Controller Class. 
    /// </summary>
    public class ControllerAppBase : Controller
    {

        private IUnitOfWorkFactory _uowFactory = null;
        private IApplicationService _appService = null;
        private ICustomerService _custService = null;
        private IClassifierService _classifierService = null;

        public ControllerAppBase(IApplicationService appService)
        {
            _appService = appService;
        }

        protected IUnitOfWorkFactory UnitOfWorkFactory    
        {
            get
            {
                if (_uowFactory == null)
                    _uowFactory = _appService.GetUnitOfWorkFactory();
                return _uowFactory;
            }
        }

        protected ICustomerService CustomerService    
        {
            get
            {
                if (_custService == null)
                    _custService = _appService.GetCustomerService();
                return _custService;
            }
        }

        protected IClassifierService ClassifierService
        {
            get
            {
                if (_classifierService == null)
                    _classifierService = _appService.GetClassifierService();
                return _classifierService;
            }
        }

        /// <summary>
        /// Instantiate the Model to be passed to the view
        /// </summary>
        /// <remarks>By instantiating all ViewData Models in a single method you can add ViewData that is accessible on all Views e.g. User specific information</remarks>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        protected T CreateViewData<T>()
        {
            var viewData = Activator.CreateInstance<T>();
            
            return viewData; 
        }


    }
}